package com.lablzh.gdxy.controller;

import com.lablzh.gdxy.entity.admin.*;
import com.lablzh.gdxy.service.CollegesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@RequestMapping("/colleges")
public class CollegesController {
    @Autowired
    private CollegesService collegesService;

    @PreAuthorize("hasAnyRole('admin')")
    @PostMapping("/college")
    public String addCollege(@RequestBody College college){
        return collegesService.addCollege(college);
    }

    @GetMapping("/collegeById")
    public College getCollegeById(@RequestParam ("ID")Integer id){
        return collegesService.getCollegeById(id);
    }

    @PreAuthorize("hasAnyRole('admin')")
    @PutMapping("/college")
    public String updateCollege(@RequestBody College college){
        return collegesService.updateCollege(college);
    }

    @PreAuthorize("hasAnyRole('admin')")
    @DeleteMapping("/college")
    public String deleteCollege(@RequestParam ("ID")Integer id){
        return collegesService.deleteCollege(id);
    }

    @GetMapping("/college")
    public List<College> getAllCollege(){
        return collegesService.getAllCollege();
    }


    @PreAuthorize("hasAnyRole('admin')")
    @PostMapping("/major")
    public String addMajor(@RequestBody Major major){
        return collegesService.addMajor(major);
    }

    @GetMapping("/majorById")
    public Major getMajorById(@RequestParam ("ID")Integer id){
        return collegesService.getMajorById(id);
    }

    @PreAuthorize("hasAnyRole('admin')")
    @PutMapping("/major")
    public String updateMajor(@RequestBody Major major){
        return collegesService.updateMajor(major);
    }

    @PreAuthorize("hasAnyRole('admin')")
    @DeleteMapping("/major")
    public String deleteMajor(@RequestParam("ID") Integer id){
        return collegesService.deleteMajor(id);
    }

    @GetMapping("/majorByCollege")
    public List<Major> getMajorByCollege(@RequestParam("college") String college){
        return collegesService.getMajorByCollege(college);
    }


    @PreAuthorize("hasAnyRole('admin')")
    @PostMapping("/classes")
    public String addClasses(@RequestBody Classes classes){
        return collegesService.addClasses(classes);
    }

    @GetMapping("/classesById")
    public Classes getClassesById(@RequestParam("ID") Integer id){
        return collegesService.getClassesById(id);
    }
    @PreAuthorize("hasAnyRole('admin')")
    @PutMapping("/classes")
    public String updateClasses(@RequestBody Classes classes){
        return collegesService.updateClasses(classes);

    }
    @PreAuthorize("hasAnyRole('admin')")
    @DeleteMapping("/classes")
    public String deleteClasses(@RequestParam("ID") Integer id){
        return collegesService.deleteClasses(id);
    }
    @GetMapping("/classesByMajor")
    public  List<Classes> getClassesByMajor(@RequestParam("major") String major){
        return collegesService.getClassesByMajor(major);
    }


    @PostMapping("/department")
    @PreAuthorize("hasAnyRole('admin')")
    public String addDepartment(@RequestBody Department department){
        return collegesService.addDepartment(department);
    }
    @GetMapping("/departmentById")
    public Department getDepartmentById(@RequestParam("ID") Integer id){
        return collegesService.getDepartmentById(id);
    }
    @PutMapping("/department")
    @PreAuthorize("hasAnyRole('admin')")
    public String updateDepartment(@RequestBody Department department){
        return collegesService.updateDepartment(department);
    }
    @PreAuthorize("hasAnyRole('admin')")
    @DeleteMapping("/department")
    public String deleteDepartment(@RequestParam("ID") Integer id){

        return collegesService.deleteDepartment(id);
    }
    @PreAuthorize("hasAnyRole('admin','teacher','instructor')")
    @GetMapping("/departmentByCollege")
    public List<Department> getDepartmentByCollege(@RequestParam("college") String college){
        return collegesService.getDepartmentByCollege(college);
    }


    @PreAuthorize("hasAnyRole('admin')")
    @PostMapping("/lab")
    public String addLab(@RequestBody Lab lab){
        return collegesService.addLab(lab);
    }

    @PreAuthorize("hasAnyRole('admin')")
    @PutMapping("/lab")
    public String updateLab(@RequestBody Lab lab){
        return collegesService.updateLab(lab);
    }

    @PreAuthorize("hasAnyRole('admin')")
    @GetMapping("/labById")
    public Lab getLabById(@RequestParam("ID") Integer id){
        return collegesService.getLabById(id);
    }

    @GetMapping("/lab")
    public List<Lab> getAllLab(){
        return collegesService.getAllLab();
    }

    @DeleteMapping("/lab")
    @PreAuthorize("hasAnyRole('admin')")
    public String deleteLab(@RequestParam("ID") Integer id){
        return collegesService.deleteLab(id);

    }
}
